﻿

using System;
using System.Data;
using Model;
namespace Dal
{
	public class BaoMing2Dal
	{
		public BaoMing2Dal()
		{
		}
 		#region Insert
 		public static int Insert(BaoMing2 baoMing2)
		{	
			string sql = @"Insert Into BaoMing2 (
					OrderNO,
					BabyName,
					ParentName,
					ParentEducation,
					Mobile,
					ParentSkill,
					WorkUnit,
					Resources,
					Notes,
					Status,
					CheckInfos,
					UserId,
					AddTime
				) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}',{9},'{10}',{11},'{12}')";
			sql = string.Format(sql,
					SqlHelper.String(baoMing2.OrderNO),
					SqlHelper.String(baoMing2.BabyName),
					SqlHelper.String(baoMing2.ParentName),
					SqlHelper.String(baoMing2.ParentEducation),
					SqlHelper.String(baoMing2.Mobile),
					SqlHelper.String(baoMing2.ParentSkill),
					SqlHelper.String(baoMing2.WorkUnit),
					SqlHelper.String(baoMing2.Resources),
					baoMing2.Notes,
					baoMing2.Status,
					SqlHelper.String(baoMing2.CheckInfos),
					baoMing2.UserId,
					baoMing2.AddTime
				);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
		
		#region Update
 		public static int Update(BaoMing2 baoMing2)
		{	
			string sql = @"Update BaoMing2 set 

					OrderNO= '{0}',
					BabyName= '{1}',
					ParentName= '{2}',
					ParentEducation= '{3}',
					Mobile= '{4}',
					ParentSkill= '{5}',
					WorkUnit= '{6}',
					Resources= '{7}',
					Notes= '{8}',
					Status= {9},
					CheckInfos= '{10}',
					UserId= {11},
					AddTime= '{12}'
				where

					Id= {13}";
			sql = string.Format(sql,
					SqlHelper.String(baoMing2.OrderNO),
					SqlHelper.String(baoMing2.BabyName),
					SqlHelper.String(baoMing2.ParentName),
					SqlHelper.String(baoMing2.ParentEducation),
					SqlHelper.String(baoMing2.Mobile),
					SqlHelper.String(baoMing2.ParentSkill),
					SqlHelper.String(baoMing2.WorkUnit),
					SqlHelper.String(baoMing2.Resources),
					baoMing2.Notes,
					baoMing2.Status,
					SqlHelper.String(baoMing2.CheckInfos),
					baoMing2.UserId,
					baoMing2.AddTime,
					baoMing2.Id);
			return SqlHelper.ExecSql(sql);
		}
		#endregion
 
 

 		#region Delete
 		public static int Delete(Int32 id)
		{
		
			string sql = @"Delete from BaoMing2 where 
					Id= {0}";
			sql = string.Format(sql,
					id
);
			return SqlHelper.ExecSql(sql);
		} 
		#endregion
 
 		#region Select
 		
 		public static DataSet Select()
		{
			string sql = "select a.* from BaoMing2 a "; 
			return SqlHelper.Select(sql);
		}
				
		public static BaoMing2 Select(Int32 id)
		{
			BaoMing2 baoMing2 = null;
			string sql = @"select a.* from BaoMing2 a  where
					a.Id= {0}
";
			sql = string.Format(sql,
					id
);
			DataSet ds = SqlHelper.Select(sql);
			if(SqlHelper.HasRow(ds))
				baoMing2 = new BaoMing2(ds.Tables[0].Rows[0]);					
			return baoMing2;
		}
		
		public static DataSet Select(string where)
		{ 
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from BaoMing2 a  where 1=1 " + where ;
			return SqlHelper.Select(sql);
		}
		
		public static DataSet SelectForList(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;
						
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;
			string sql = "select a.* from BaoMing2 a where 1=1 " + where;
                
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}		
		public static DataSet Select(string where,int pageIndex,int pageSize,bool bCount,out int count )
		{
			count = 0;			
			if (where.Trim().ToLower().StartsWith("where"))
				where = where.Substring(5);
			if (!where.Trim().ToLower().StartsWith("and") && where.Trim().Length > 0)
				where = " and " + where;			
			string sql = "select a.* from BaoMing2 a  where 1=1 " + where;
			return SqlHelper.Select(sql,pageSize,pageIndex,bCount,ref count);
		}
		#endregion
	}
}
